<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<script>
description('Check stepping-up and -down for month input fields from renderer.');
if (!window.eventSender)
    debug('This test requires eventSender.');

var input = document.createElement('input');
input.type = 'month';
document.body.appendChild(input);

function setInputAttributes(value, min, max) {
    input.value = value;
    input.min = min;
    input.max = max;
}

function stepUp(value, min, max) {
    setInputAttributes(value, min, max);
    eventSender.keyDown('ArrowUp');
    return input.value;
}

function stepDown(value, min, max) {
    setInputAttributes(value, min, max);
    eventSender.keyDown('ArrowDown');
    return input.value;
}

input.focus();
debug('Function arguments are (value, min, max, [keySequence]).');
debug('Month');
shouldBeEqualToString('stepUp("2000-05", "2000-05", "2000-10")', '2000-06');
shouldBeEqualToString('stepDown("2000-05", "2000-05", "2000-10")', '2000-10');
shouldBeEqualToString('stepUp("2000-05", "2000-02", "2000-05")', '2000-02');
shouldBeEqualToString('stepDown("2000-05", "2000-02", "2000-05")', '2000-04');
shouldBeEqualToString('stepUp("2000-05", "2000-08", "2000-10")', '2000-08');
shouldBeEqualToString('stepDown("2000-05", "2000-08", "2000-10")', '2000-10');
shouldBeEqualToString('stepUp("2000-05", "2000-03", "2000-03")', '2000-03');
shouldBeEqualToString('stepDown("2000-05", "2000-03", "2000-03")', '2000-03');
shouldBeEqualToString('stepUp("2000-05", "2000-03", "2001-05")', '2000-06');
shouldBeEqualToString('stepDown("2000-05", "2000-05", "2001-08")', '2000-04');

debug('Year');
eventSender.keyDown('ArrowRight');
shouldBeEqualToString('stepUp("2000-01", "2000-01", "2009-12")', '2001-01');
shouldBeEqualToString('stepDown("2000-01", "2000-01", "2009-12")', '2009-01');
shouldBeEqualToString('stepUp("2000-01", "1990-01", "2000-12")', '1990-01');
shouldBeEqualToString('stepDown("2000-01", "1990-01", "2000-12")', '1999-01');
shouldBeEqualToString('stepUp("275760-01", "1990-01", null)', '1990-01');
shouldBeEqualToString('stepDown("1990-01", "1990-01", null)', '275760-01');
shouldBeEqualToString('stepUp("2000-01", null, "2000-12")', '0001-01');
shouldBeEqualToString('stepDown("0001-01", null, "2000-12")', '2000-01');
shouldBeEqualToString('stepUp("1990-01", "2000-01", "2009-12")', '2000-01');
shouldBeEqualToString('stepDown("1990-01", "2000-01", "2009-12")', '2009-01');
shouldBeEqualToString('stepUp("2020-01", "2000-01", "2000-12")', '2000-01');
shouldBeEqualToString('stepDown("2020-01", "2000-01", "2000-12")', '2000-01');

debug('');
input.remove();
</script>
</body>
</html>
